package cn.dgut.changeManager;

import cn.dgut.Utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

@WebServlet("/AddRecruitment")
public class AddRecruitmentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String title = request.getParameter("title");
        String phone = request.getParameter("phone");
        String wage = request.getParameter("wage");
        String info = request.getParameter("content");


        String sql = "INSERT INTO `Recruit` VALUES(null,'"+title+"','"+phone+"',"+wage+",'"+info+"')";

        JDBCUtils jdbcUtils = new JDBCUtils();
        int status = jdbcUtils.querySQL(sql);
        HttpSession session = request.getSession(true);
        session.setAttribute("isRight", status);
        response.sendRedirect("/backstage/main_page.jsp?page=6");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}